﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RoutingDaemon.Utilities;
using RoutingDaemon.Entities;

namespace RoutingDaemon.ServerInterface.CommandHandlers
{
    class REMOVEUSERCommandHandler : CommandHandlerBase
    {
        public override string HandleCommand(global::RoutingDaemon.ServerInterface.Commands.DaemonCommandBase command)
        {
            if (command is Commands.REMOVEUSERCommand)
            {
                Commands.REMOVEUSERCommand removeUserCommand = (Commands.REMOVEUSERCommand)command;

                if (string.IsNullOrEmpty(removeUserCommand.Nickname))
                {
                    return "Error";
                }
                // remove the nick from the local users list
                User user = new User()
                {
                    Nickname = removeUserCommand.Nickname
                };

                Backend.DaemonBackEnd.Instance.LocalNode.Users.Remove(user);
                // trigger LSA update
                Backend.DaemonBackEnd.Instance.UpdateRoutingTable();
                return Responses.GetResponse(ResponseCodes.OK,string.Empty);
            }
            else
            {
                throw new ArgumentException();
            }
            
        }
    }
}
